/**
 * Project Name:zbj-real-name-core-facade-impl
 * File Name:ToolsUtil.java
 * Package Name:com.zhubajie.real.name.core.util
 * Date:2016年8月11日下午1:34:07
 * Copyright (c) 2016, www.zbj.com All Rights Reserved.
 *
*/

package com.inoneone.youba.mcht.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ClassName:日期工具类 <br/>
 * Function: TODO 描述功能. <br/>
 * Date: 2016年8月11日 下午1:34:07 <br/>
 * 
 * @author 姬远玄
 * @version
 * @since JDK 1.7
 * @see
 */
public class DateUtil {

	/**
	 * 
	 * parseDate:(字符串解析为日期对象).
	 * 
	 * @author zhoudy
	 * @param dateStr
	 * @param pattern
	 * @return
	 * @throws ParseException
	 * @since JDK 1.6
	 */
	public static Date parseDate(String dateStr, String pattern) {
		SimpleDateFormat sf = new SimpleDateFormat(pattern);
		Date date;
		try {
			date = sf.parse(dateStr);
		} catch (ParseException e) {

			throw new RuntimeException("日期格式解析出错", e);

		}
		return date;
	}

	/**
	 * 
	 * changeDateFromat:(转换日期格式化字符串).
	 * 
	 * @author zhoudy
	 * @param date
	 * @param oldFomat
	 * @param newFomat
	 * @return
	 * @throws ParseException
	 * @since JDK 1.6
	 */
	public static String changeDateFromat(String date, String oldFomat, String newFomat) throws ParseException {
		Date temp = parseDate(date, oldFomat);
		return formatDate(temp, newFomat);
	}

	/**
	 * 
	 * formatDate:(以指定的格式来格式化日期).
	 * 
	 * @author zhoudy
	 * @param date
	 * @param format
	 * @return
	 * @since JDK 1.6
	 */
	public static String formatDate(Date date, String format) {
		SimpleDateFormat sf = new SimpleDateFormat(format);
		return sf.format(date);

	}

	/**
	 * Description: 日期格式化</br>
	 * Date: 2017-06-20 17:16:52</br>
	 *
	 * @param
	 * @return
	 * @author 姬远玄
	 * @since JDK 1.7
	*/
	public static String formatDate(Date date)
	{
		return formatDate(date, "yyyy-MM-dd HH:mm:ss");
	}
}
